﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HelpCentral.ClientManager.Web.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Client Manager</title>
    <script type="text/javascript">
        function GenerateLicense(target) {
            var search = document.getElementById(target);

            if (search) {
                // uuid generation by broofa (http://stackoverflow.com/users/109538/broofa)
                // broofa is not associated with nor endorses this project
                // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
                var value = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
                    var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
                    return v.toString(16);
                }).toUpperCase();

                search.value = value;
            }
        }

        function SaveClient() {
            
        }
    </script>
    <script src="Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ListView runat="server" id="lstClients" DataSourceID = "objClients">
            <LayoutTemplate>
                <table>
                    <thead>
                        <tr>
                            <th>Actions</th>
                            <th>Client Name</th>
                            <th>License Key</th>
                            <th>Activate Date</th>
                            <th>Deactivate Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr id="itemPlaceholder" runat="server" />
                    </tbody>
                </table>
            </LayoutTemplate>
            <ItemTemplate>
                <tr>
                    <td>
                        <asp:Button runat="server" id="btnEdit" Text="Edit" />
                    </td>
                    <td>
                        <%#Eval("Name") %>
                    </td>                    
                    <td>
                        <%#Eval("License") %>
                    </td>
                    <td>
                        <%#Eval("ActivateDate") %>
                    </td>
                    <td>
                        <%#Eval("DeactivateDate") %>
                    </td>
                </tr>
            </ItemTemplate>
            <EmptyDataTemplate>
            <table>
                <tr><td>
                    There are no clients in the database.
                </td></tr>
            </table>
            </EmptyDataTemplate>
        </asp:ListView>

        <div id="addClient">
            <h1>Add Client</h1>
            Use this form to create a new client.

            <table>
                <tr>
                    <td><asp:Label runat="server" id="lblClientName" Text="Client Name:" AssociatedControlID="txtClientName" EnableViewState="False" /></td>
                    <td><asp:TextBox runat="server" id="txtClientName" /></td>
                </tr>
                <tr>
                    <td><asp:Label runat="server" id="lblLicense" Text="License:" AssociatedControlID="txtLicense" EnableViewState="False" /></td>
                    <td><asp:TextBox runat="server" id="txtLicense" ReadOnly="True" /> <input type="button" Value="Generate" OnClick="GenerateLicense('<%= txtLicense.ClientID %>')" /></td>
                </tr>
                <tr>
                    <td><asp:Label runat="server" id="lblActivateDate" Text="Activate Date:" AssociatedControlID="txtActivateDate" EnableViewState="False" /></td>
                    <td><asp:TextBox runat="server" id="txtActivateDate" /></td>
                </tr>
                <tr>
                    <td><asp:Label runat="server" id="lblDeactivateDate" Text="Deactivate Date:" AssociatedControlID="txtDeactivateDate" EnableViewState="False" /></td>
                    <td><asp:TextBox runat="server" id="txtDeactivateDate" /></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td><asp:Button runat="server" id="btnSave" Text="Save Client" OnClientClick="SaveClient(); return false;" /></td>
                </tr>
            </table>
        </div>
    </div>

    <asp:ObjectDataSource runat="server" id="objClients" TypeName = "HelpCentral.ClientManager.Web.Default" SelectMethod="GetClients" />
    </form>
</body>
</html>
